package org.eenie.kdassistant.ui;

import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.yunda.crypt.NativeEncryption;

import org.eenie.kdassistant.R;
import org.eenie.kdassistant.net.ParamsAnalog;
import org.eenie.kdassistant.ui.scan.ScanActivity;
import org.eenie.kdassistant.ui.setting.SettingActivity;

public class MainActivity extends BaseActivity {

    private ParamsAnalog mParamsAnalog;

    private MenuItem mSetMenuItem;


    private String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAICDCKYFxQ9Yc6QQfUSkGQXEhbvjlchxF4McXNuJy3y/jNEdiHr4S6BZRfLemCRB+z4xluKT5ELSrRd7sOwa7XcCAwEAAQ==";
    private String token = "CFKEiUhU8aW7jD-faXi43B2V";


    @Override
    public int initContentView() {
        return R.layout.activity_main;
    }

    @Override
    public void initInjector() {
        mParamsAnalog = getApplicationComponent().getParamsAnalog();
    }

    @Override
    public void initUiAndListener() {




        findViewById(R.id.btn_scan_qs).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                EDOutputData outputData = new EDOutputData();

//                int res = NativeEncryption.JNI_IEncrypt("111111", outputData);
//
//                System.out.println("encode res = " + res + " data = " + outputData.GetData());


                startActivity(new Intent(mContext, ScanActivity.class)
                        .putExtra("express_type", 0));
            }
        });
        findViewById(R.id.btn_scan_dj).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                int res = NativeEncryption.JNI_EDCodeInstance("bapp.yundasys.com",
//                        2059,
//                        token,
//                        "5.6.0",
//                        publicKey);
//
//                System.out.println("init res = " + res);
                startActivity(new Intent(mContext, ScanActivity.class)
                        .putExtra("express_type", 1));
            }
        });


        NativeEncryption.JNI_EDCodeInstance("bapp.yundasys.com", 2059, mParamsAnalog.getYd_token(), "5.6.0", mParamsAnalog.getYd_public_key());



    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        mSetMenuItem = menu.add("设置");
        mSetMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);

        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getTitle().equals("设置")) {
            startActivity(new Intent(mContext, SettingActivity.class));
        }

        return super.onOptionsItemSelected(item);
    }
}
